package com.huasan.www.demon.rest.resource;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.server.mvc.Viewable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
@Path("/mock")
public class Mock {
	
	private static final Logger logger = LoggerFactory.getLogger(Mock.class);
	
	private final String pieData2 = "[{\"name\":\"时间\",\"id\":\"time\",\"data\": [\"一号楼\", \"二号楼\", \"三号楼\", \"四号楼\"]}," +
			"{\"name\":\"数值\",\"id\":\"data\",\"data\": [\"200\",\"100\",\"300\",\"300\" ]}]" ;
	
	@GET
	@Path("/page")
	@Produces({"text/html"})
	public Viewable getPage(){
		Map map = new HashMap();
		map.put("test", "你好");
		return new Viewable("/WEB-INF/index", map);
	}
	
	@GET
	@Path("/getTest")
	@Produces({MediaType.APPLICATION_JSON})
	public String getTest(@QueryParam("id") String id){
		logger.error("abcd");
		return pieData2;
	}
	
	@POST
	@Path("/postTest")
	@Produces({MediaType.APPLICATION_JSON})
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public String postTest(@FormParam("id") String id){
		return pieData2;
	}
	
	@PUT
	@Path("/putTest")
	@Produces({MediaType.APPLICATION_JSON})
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public String putTest(@FormParam("id") String id){
		return pieData2;
	}
	
	@DELETE
	@Path("/deleteTest")
	@Produces({MediaType.APPLICATION_JSON})
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public String deleteTest(@FormParam("id") String id){
		return pieData2;
	}
}
